﻿var _config = new Object({ url: "AjaxPages/AjaxChatRequest.ashx", async: false, dataType: "json", type: "POST", msgID: <%=Application["maxCount"].ToString()%>, msgName: "Guest", msgIP: "<%=Request.UserHostAddress%>" }); var ChatMsgObjArray = new Array; ChatMsgObj = function() { this.msgID; this.msgName; this.msgIP; this.msgTime; this.msgText }; $(document).ready(function() { GetMsgJsonInfo(); $("#txtMsgName").select() }); function GetMsgJsonInfo() { GetMsgIDToLastJson(_config.msgID) }
function ChangeMsgName(btn) { var _msgName = $("#txtMsgName").val(); if (_msgName != "" && _msgName != "Guest") { _msgName = _msgName.substring(0, 8); _config.msgName = _msgName; btn.disabled = true; $("#msgText_textarea").attr("disabled", false); $("#SendMsg_ShowMsg").text("\u59d3\u540d\u4fee\u6539\u6210\u529f"); $("#msgText_textarea").focus() } else $("#SendMsg_ShowMsg").text("\u59d3\u540d\u4e0d\u80fd\u4e3a\u7a7a/Guest") }
function GetMsgIDToLastJson(LastID) { $.ajax({ url: _config.url, data: { _type: "GetLastToEnd", LastID: LastID }, async: _config.async, dataType: _config.dataType, type: _config.type, success: function(data) { BindObjJson(data); if (data.length != 0) _config.msgID = data[data.length - 1]["msgID"]; setTimeout(GetMsgJsonInfo, 1E3) } }) }
function SetSaveObjArray(data) { for (var i = 0; i < data.length; i++) { var _obj = new ChatMsgObj; _obj.msgID = data[i]["msgID"]; _obj.msgName = data[i]["msgName"]; _obj.msgIP = data[i]["msgIP"]; _obj.msgTime = data[i]["msgTime"]; _obj.msgText = data[i]["msgText"]; ChatMsgObjArray.push(_obj) } }
function BindObjJson(data) {
    for (var i = 0; i < data.length; i++) {
        var _html = '<div class="ShowMsg"><div><span class="ShowSpanName">' + data[i]["msgName"] + '</span><span class="ShowSpanIP">' + data[i]["msgIP"] + '</span><span class="ShowSpanTime">' + data[i]["msgTime"] + '</span></div><div class="ShowMsgText"><p id="ShowMsg_P' + data[i]["msgID"] + '"></p></div></div>'; $("#Main_Show_Msg").append(_html); $("#ShowMsg_P" + data[i]["msgID"]).text(data[i]["msgText"]); if ($.trim(_config.msgName) != $.trim(data[i]["msgName"])) ChangeWindowsTitle(data[i]["msgName"]);
        getScrollToEnd()
    } 
} function ChangeWindowsTitle(msgName) { if (msgName != "") { document.title = "\u7b80\u5355\u804a\u5929\u5ba4LiuJu----\u4f60\u6709[" + msgName + "]\u53d1\u6765\u7684\u65b0\u6d88\u606f"; setTimeout("ChangeWindowsTitle('')", 4E3) } else document.title = "\u7b80\u5355\u804a\u5929\u5ba4LiuJu" }
function SendObj() { var _obj = new ChatMsgObj; _obj.msgName = _config.msgName; _obj.msgIP = _config.msgIP; _obj.msgTime = Date().toString(); _obj.msgText = $("#msgText_textarea").val(); if (_obj.msgText == "") return; $.post(_config.url, { _type: "SendChatMsg", msgName: _obj.msgName, msgIP: _obj.msgIP, msgTime: _obj.msgTime, msgText: _obj.msgText }, function(data) { $("#msgText_textarea").val(""); document.getElementById("msgText_textarea").focus(); $("#SendMsg_ShowMsg").text("\u4fe1\u606f\u53d1\u9001\u6210\u529f" + data["msgTime"]) }, _config.dataType) }
function getScrollToEnd() { var MsgDiv = document.getElementById("Main_Show_Msg"); MsgDiv.scrollTop = MsgDiv.scrollHeight - MsgDiv.clientHeight } function CtrlAndEnter(e) { if (e.ctrlKey && e.keyCode == 13) SendObj() } function EnterToChangeNmae(e) { if (e.keyCode == 13) $("#btn_chageName").click() };